<template>
  <div class="app-container">


    <el-table v-loading="loading" :data="tastList">
      <el-table-column label="流程ID" align="center" prop="id"/>
      <!-- <el-table-column label="流程名称" align="center" prop="instanceName"/> -->
      <el-table-column label="任务节点名称" align="center" prop="name"/>
      <!-- <el-table-column label="任务状态" align="center" prop="status"/> -->
      <el-table-column label="办理人" align="center" prop="assignee"/>
      <el-table-column label="创建时间" align="center" prop="createdDate"/>

      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="examineAndApprove (scope.row)"
          >审批
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <el-col :span="24">
      <el-pagination
        background
        :page-sizes="[3, 5, 10]"
        :page-size="queryParams.pageSize"
        :current-page="queryParams.pageNum"
        layout="total, sizes, prev, pager, next"
        :total="total"
        @current-change="handleCurrentChange"
        @next-click="nextPage"
        @prev-click="prevPage"
        @size-change="sizePage"
      ></el-pagination>
    </el-col>
    <!-- <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    /> -->

    <!-- 审批对话框 -->
    <el-dialog title="审核对话框" :visible.sync="dialogVisible">
      <!-- 审核意见输入框 -->
      <el-form>
        <el-form-item label="审核意见">
          <el-input v-model="reviewComment"></el-input>
        </el-form-item>
      </el-form>

      <!-- 通过和不通过选择器 -->
      <div>
        <span>审核结果：</span>
        <el-switch v-model="isApproved" active-text="通过" inactive-text="不通过"></el-switch>
      </div>

      <!-- 按钮 -->
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取消</el-button>
        <el-button type="primary" @click="submitReview">提交</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>


  import {listTask, formDataShow, formDataSave} from "@/api/activiti/task";
  import leaveHistoryForm from "@/views/workflow/leave/leaveHistoryForm";
  import Cookies from "js-cookie";
  export default {
    name: "Leave",
    components: {leaveHistoryForm},
    data() {
      return {
        id:'',
        definitionKey: '',
        businessKey: '',
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 请假表格数据
        tastList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        dialogVisible: false,

        isApproved:true,
        pass:'',
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          name:Cookies.get("username")
        },
        // 表单参数
        form: {
          formData:[]
        },
        // 表单校验
        rules: {}
      };
    },
    created() {
      this.getList();
    },
    methods: {
      /** 查询请假列表 */
      getList() {
        this.loading = true;
        //  this.queryParams.name = Cookies.get("username")
        this.$axios.post("/ap/task/getTaskList",this.queryParams)
        .then(response => {
          // this.tastList = response.rows;
          // this.total = response.total;
          // this.loading = false;
        this.tastList = response.data.data.list;
        this.total = response.data.data.total;
        this.pageNum = response.data.data.pageNum;
        this.pageSize = response.data.data.pageSize;
        this.loading = false;
        });
      },

      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.definitionKey = '',
          this.businessKey = '',
          this.form = {
            formData:[],
          };
        this.resetForm("form");
      },

    submitReview(){
      const pass = this.isApproved ? 1 : 0;
      const isSpecialPriceRequested = 1;
            let param = {}
            param.status = 1
            param.pass = pass
            param.id = this.id
            if(this.businessKey == 'customer'){
              this.$axios.post("/ap/task/complete",param)
            .then(res=>{
                alert(res.data)
        })
            }else if(this.businessKey == 'order'){
              this.$axios.post("/ap/task/completeOrder",param)
            .then(res=>{
                alert(res.data)
        })
            }else if(this.businessKey == 'distributor'){
              this.$axios.post("/ap/task/completeDistributor",param)
            .then(res=>{
                alert(res.data)
        })
            }else if(this.businessKey == 'distributorOrder'){
              this.$axios.post("/ap/task/distributorOrder",param)
            .then(res=>{
                alert(res.data)
        })
            }           
      },
      /** 审批按钮操作 */
      examineAndApprove(row) {
        console.log(row)
        this.dialogVisible = true
        this.id = row.id
        this.businessKey = row.businessKey
      },
      /** 提交按钮 */
      submitForm() {
        formDataSave(this.id,this.form.formData).then(response => {
          this.msgSuccess("审批成功");
          this.open = false;
          this.getList();
        });
      },
      handleCurrentChange(val) {
      this.pageNum = val;
      this.queryInspection();
    },
    nextPage(val) {
      //下一页
      this.pageNum = val;
      this.queryInspection();
    },
    prevPage(val) {
      //上一页
      this.pageNum = val;
      this.queryInspection();
    },
    sizePage(val) {
      //改变每页条数
      this.pageSize = val;
      this.pageNum = 1;
      this.queryInspection();
    },
    conditionalQuery() {
      this.pageNum = 1;
      this.queryInspection();
    },
    }
  };
</script>
